<template>
	<view>
		<view class="flex justify-between padding-left-xs">
			<text :class="'margin-right-sm '+ (_type==0?'text-blue':'text-green')">{{_item.name}}</text>
			<text class="text-grey">提交于 {{getDateDiff(_item.createTime)}}</text>
		</view>
		<view class="bg-white padding-lr-xs padding-top-sm" v-if="_item.images.length>0">
			<view class="grid col-5 grid-square">
				<view class="bg-img" @tap="ViewImage(index)" v-for="(item,index) in _item.images" :key="index" :style="[{ backgroundImage:'url(' + _item.images[index] + ')' }]"></view>
			</view>
		</view>
		<view class="flex justify-end margin-top-sm margin-left-xs align-center text-lg">
			<view class="text-bold text-red text-sm">{{_item.statusStr}}</view>
			<button class="cu-btn radius sm bg-red margin-left-lg" @tap="remove(_item)">
				删除
			</button>
			<button class="cu-btn radius sm bg-orange margin-left-lg" @tap="goEdit(_item)">
				修改
			</button>
			<button class="cu-btn radius sm bg-blue margin-left-lg" @tap="showDetail(_item)">
				详情
			</button>
		</view>
	</view>
</template>

<script>
	import {getDateDiff} from "@/utils/date/date.js"
	import * as confirm from '@/common/confirm.js'
	
	export default {
		data() {
			return {
				_item:{},
				_type:0
			};
		},
		name: 'comment-item',
		props: {
			item:{
				type:Object,
				default:{}
			},
			type:{
				type:Number,
				default:0
			}
		},
		created() {
			this._item=this.item
			this._item.image=this.item.img
			this._item.images=this.item.imageList
			
			this._type=this.type
		},
		methods: {
			getDateDiff(date){
				return getDateDiff(date)
			},
			ViewImage(e) {
				this.$emit("viewImage",
				{
					title:this._item.name,
					avatar:this._item.image,
					images:this._item.images,
					now:e})
			},
			goDetail(item){
				this.$emit("goDetail")
			},
			goEdit(item){
				this.$emit("goEdit")
			},
			remove(item){
				let _this=this
				confirm.choose('删除该推荐?',(item)=>{
					uni.showLoading({
						title:'提交中'
					})
					this.$api.post('/user/remove_recommend',{id:item.id}).then(res => {
						uni.hideLoading()
						uni.showToast({
							title:'删除成功',
							icon:'none'
						})
						
						this.$emit("goRemove",item)
						
					}).catch(()=>{
						uni.hideLoading()
					})
				},item)
			},
			showDetail(item){
				this.$emit("showDetail",item)
			}
		}
	}
</script>

<style scoped>
</style>